// pages/logistics-detail/logistics-detail.js
const apiurl = require('../../config').apiurl;
import {
  Pulibc
} from '../../models/public.js'
const pulibc = new Pulibc()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    wuliu: ['已接收', '抵达深圳', '抵达广州', '正在打包'],
    shippingInfo: {},
    logisticsList: [],
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    
    console.log(options.order_id)
    var order_id = options.order_id
    this.getLogisticsData(order_id);
  },
  getLogisticsData(order_id) {
    let that = this;
    let url = apiurl + '/order/info';
    let params = {};
    params.key = wx.getStorageSync('key');
    params.order_id = order_id
    wx.request({
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      url: url,
      data: params,
      
      success(res) {
        console.log(res)
        // console.log(res.data.datas)
        if (res.data.code == 200){

        }
        let shippingInfo = res.data.datas.info;
        let logisticsList = res.data.datas.result;
        console.log(logisticsList)
        if (logisticsList.returnCode==500){
          that.setData({
            shippingInfo
          })
          return;
        }
        if (!logisticsList.result){
          logisticsList.map(item => {
            
            if (54 < item.context.length <= 70) {
              item.size = 'on-middle';
            }
            if (item.context.length > 70) {
              item.size = 'on-max';
            }
            if (item.context.length <= 50) {
              item.size = 'on';
            }
          })
           logisticsList.reverse()
        }
       
        that.setData({
          shippingInfo,
          logisticsList
        })
        console.log('logisticsList', that.data.logisticsList)
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    if (wx.getStorageSync("key") == false) {
      wx.navigateTo({
        url: "../register/register"
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})